package com.leoman.utils;

import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.WxCpMessage;

import java.util.*;

/**
 * Created by Administrator on 2016/3/10.
 */
public class SendMsgWork {

    private static Map<String, Object> map = new HashMap<String, Object>();

    private Timer timer = null;

    private Integer type;

    private String content;

    public SendMsgWork(Integer type, String content) {
        timer = new Timer();
        this.type = type;
        this.content = content;
        timer.schedule(new MyWork(), new Date());
    }

    class MyWork extends TimerTask {
        @Override
        public void run() {
            try {
                doExecute();
                timer.cancel();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    private void doExecute() {
        System.out.println("=============================================================开始发送消息=============================================================");
        try {
            WxCpService wxCpService;
            /*if (type == 1) {*/
                // 协和齿环
                wxCpService = (WxCpService) BeanUtil.getBean("wxCpService1");
                wxCpService.messageSend(WxCpMessage.TEXT().content(content).agentId("1").toUser("zhangzan").build());
            /*} else {
                // 泛洲中越
                wxCpService = (WxCpService) BeanUtil.getBean("wxCpService");
                wxCpService.messageSend(WxCpMessage.TEXT().content(content).agentId("2").toUser("xch").build());
            }*/
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("=============================================================结束发送消息=============================================================");
    }
}
